<template>
	<div class="ds-setting-container">
		<div class="ds-setting-side">
			<ul>
				<li :class="{ 'ds-side-selected':data.currentSelect == 'theme'}" @click="onSideSelect('theme')">颜色</li>
				<li :class="{ 'ds-side-selected':data.currentSelect == 'display'}" @click="onSideSelect('display')">壁纸</li>
			</ul>
		</div>
		<div class="ds-setting-panel">
			<div class="ds-theme-container" v-if="data.currentSelect == 'theme'">
				<color-picker :zIndex="0" :isWidget="true" pickerType="fk" v-model:pureColor="pureColor" format="rgb" shape="circle" useType="pure" v-model:gradientColor="gradientColor" @pureColorChange="pureColorChange" @gradientColorChange="gradientColorChange"/>
			</div>
			<div class="ds-display-container" v-if="data.currentSelect == 'display'" :style="{ background: 'url(' + data.preview + ')'  }">
				<div class="ds-display-top"></div>
				<div class="ds-display-list">
					<div class="ds-display-list-item" :class="{ 'ds-item-selected': item.selected }" v-for="(item, index) in data.imglist" :key="index" @click="onSelect(item.url)">
						<img :src="item.url" />
					</div>
				</div>
				<div class="ds-display-bottom"></div>
			</div>
		</div>
	</div>
</template>

<script setup>
import helper from '@/utils/helper'
import { reactive,ref } from 'vue'
import coreStore from '../../stores/core.js';
import { ColorPicker } from "vue3-colorpicker";
import "vue3-colorpicker/style.css";

const pureColor = ref("#71afe5");
const gradientColor = ref("linear-gradient(0deg, rgba(0, 0, 0, 1) 0%, rgba(0, 0, 0, 1) 100%)");
const $coreStore = coreStore();

let images = [
	{ url: './wall/wall-0.jpg', selected: false },
	{ url: './wall/wall-1.jpg', selected: false },
	{ url: './wall/wall-2.jpg', selected: true },
	{ url: './wall/wall-3.jpg', selected: false },
	{ url: './wall/wall-4.jpg', selected: false },
	{ url: './wall/wall-5.jpg', selected: false }
];

const data = reactive({
	currentSelect:'theme',
	currentIndex: 0, 
	timer: null,
	preview:helper.getLocalstorage('wallpaper',""),
	imglist:images,
	
});

const selectwallpaper = ()=> {
	data.imglist.forEach(item => {
		if(item.url === data.preview){
			item.selected = true
		} else {
			item.selected = false
		}
	})
}
const onSelect = (url) =>{
	data.preview = url
	$coreStore.setWallpaper(url);
	selectwallpaper()
}

const onSideSelect = function(id) {
	data.currentSelect = id;
}

const gradientColorChange = (e) => {
  //console.log(e)
  $coreStore.setThemeColor(e);
}

const pureColorChange = (e) => {
 // console.log(e)
 $coreStore.setThemeColor(e);
}
</script>
<style lang="less" scoped>
.ds-setting-container {
	background-color: var(--default-background-color);
	width: 100%;
	height: 100%;
	display: flex;
	flex-wrap: nowrap;
	flex-direction:row;
	justify-content:center;
	align-items: center;
}	
.ds-setting-side {
	background-color: rgba(230, 230, 230, 1);
	width: 20%;
	height: 100%;
}

.ds-setting-panel {
	flex:1;
	width:0;
	height: 100%;
	display: flex;
	align-items: center;
	flex-direction: column;
	justify-content: center;
}

.ds-setting-side ul {
	list-style-type: none;
	width: 100%;
	height: 100%;
	display: flex;
	align-items: center;
	flex-direction: column;
	justify-content: flex-start;
	li {
		display: flex;
		align-items: center;
		justify-content: center;
		width: 100%;
		//padding-left: 25%;
		height: 10%;
		font-weight: 600;
		//text-align:left;
	}
	li:hover {
		background-color: rgba(207, 207, 207, 1);
	}
}

.ds-side-selected {
	background-color: rgba(170, 170, 255, 1.0);
}

.ds-theme-container {
	width: 100%;
	height: 100%;
	display: flex;
	align-items: center;
	justify-content: center;
	flex-direction: row;
}

.ds-display-container {
	width: 100%;
	height: 100%;
	display: flex;
	align-items: center;
	justify-content: center;
	flex-direction: column;
}

.ds-display-top {
	width: 100%;
	height: 50%;
}

.ds-display-bottom {
	width: 100%;
	height: 10%;
}

.ds-display-list {
	flex:1;
	width: 80%;
	padding-bottom: 5%;
	background-color: rgba(0, 0, 0, 0.35);
	box-shadow: 0 10px 25px rgba(0, 0, 0, 0.6);
	border-radius: 5px;
	padding: 10px 10px;
	overflow-x: auto;
	display: flex;
	align-items: center;
	justify-content: flex-start;
	flex-direction: row;
}

.ds-display-list::-webkit-scrollbar {
	width: 3px;
	height: 5px;
}
.ds-display-list::-webkit-scrollbar-thumb {
	border-radius: 5px;
	background: #5555ff;
}
.ds-display-list::-webkit-scrollbar-track {
	-webkit-box-shadow: inset 0 0 1px rgba(0, 0, 0, 0);
	border-radius: 3px;
	background: #ffffff;
}

.ds-display-list-item {
	flex:1;
	//overflow: auto;
	margin: 5px;
	//display: inline-block;
}
.ds-display-list-item:hover {
	border: 1px solid #a0d911;
}
.ds-item-selected {
	border: 1px solid red;
}
.ds-display-list-item:active {
	border: 1px solid #a8071a;
}

.ds-display-list-item img {
	height: 120px;
}
</style>
